package com.mxpio.erp.plm.service.impl;

import com.mxpio.erp.common.plm.entity.ProjectTaskDraft;
import com.mxpio.erp.common.plm.service.ProjectTaskDraftService;
import com.mxpioframework.common.exception.MBootException;
import com.mxpioframework.jpa.query.Criteria;
import com.mxpioframework.jpa.query.Operator;
import com.mxpioframework.system.service.impl.BaseServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 项目任务草稿
 */
@Service
public class ProjectTaskDraftServiceImpl extends BaseServiceImpl<ProjectTaskDraft> implements ProjectTaskDraftService {
    /**
     * 根据任务编码或者任务草稿表
     * @param taskCode
     * @return
     */
    @Override
    @Transactional
    public ProjectTaskDraft getOne(String taskCode) {
        List<ProjectTaskDraft> drafts = this.list(ProjectTaskDraft.class, Criteria.create().addCriterion("taskCode", Operator.EQ, taskCode));
        for (ProjectTaskDraft draft : drafts){
            //当为1或者0是都代表着这个变更内容通过审核或者未通过，为null 的时候代表最新的
            if (draft.getIsTask()==null){
                return draft;
            }
        }
        throw new MBootException("没有找到任务草稿！");
    }
}
